package action;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import basic.PageInfo;
import basic.QuerySet;
import basic.ResultSet;
import basic.SortInfo;
import common.BaseAction;
import common.dict.CommonDict;
import entities.TMail;
import entities.TMerchant;
import entities.TSubject;
import interfaces.IBankService;
import interfaces.IMailService;
import interfaces.IMerchantService;
import interfaces.ISubjectService;
import net.sf.json.JSONArray;
import util.ParameterUtil;
import utils.AesUtil;
import utils.DateUtil;
import utils.ExcelUtil;
import utils.KeyUtil;
import utils.StringUtil;

public class MerchantAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7507534255609348887L;

	private IMerchantService merchantService;
	private ISubjectService subjectService;
	private IBankService bankService;
	private IMailService mailService;

	private TMerchant merchantBean;
	private List<TMerchant> merchantList;

	private String merNo;
	private String merName;
	private String merLevel;
	private String merEmail;
	private String merInfo;
	private String merIndustry;
	private String merLink;
	private String merCredential;
	private String merNumber;
	private String merPhone;
	private String merQq;
	private String merSource;
	private String merAddr;
	private String merBanker;
	private String merBank;
	private String merBranch;
	private String merAccount;
	private Double merOpen;
	private Double merSum;
	private Double merPer;
	private Double merDay;
	private Double merEnd;
	private Double merTop;
	private Double merMin;
	private Double merMax;
	private Double merReturn;
	private Double merFreq;
	private Double merLimit;
	private Double merConst;
	private Double merVenture;
	private Double merRefund;
	private Double merRefuse;
	private String merVe;
	private String merVm;
	private String merVb;
	private String merVs;
	private Double merVp;
	private Double merVd;
	private String merMe;
	private String merMm;
	private String merMb;
	private String merMs;
	private Double merMp;
	private Double merMd;
	private String merJe;
	private String merJm;
	private String merJb;
	private String merJs;
	private Double merJp;
	private Double merJd;
	private String merAe;
	private String merAm;
	private String merAb;
	private String merAs;
	private Double merAp;
	private Double merAd;
	private String merCe;
	private String merCm;
	private String merCb;
	private String merCs;
	private Double merCp;
	private Double merCd;
	private String merDe;
	private String merDm;
	private String merDb;
	private String merDs;
	private Double merDp;
	private Double merDd;
	private String merRisking;
	private String merShipping;
	private String merMailing;
	private String merNotifying;
	private String merChilding;
	private String merLimiting;
	private String merDaying;
	private String merComparing;
	private String merCounting;
	private String merBrushing;
	private String merIgnoring;
	private String merVerifying;
	private String merRefunding;
	private String merReplacing;
	private String merUsing;
	private String merState;
	private Date merDate;
	private Date merDateTop;
	private Date merDateEnd;
	private String merRemark;

	// 信息展示
	public void name() throws Exception {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html;charset=UTF-8");
		if (!merchantService.exist(merNo)) {
			response.getWriter().println("0000");
		} else {
			response.getWriter().println(merchantService.fetch(merNo).getMerName());
		}
	}

	// 信息展示
	public String show() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		} else {
			merchantBean = merchantService.fetch(merNo);
			return SUCCESS;
		}
	}

	// 商户登记
	public String edit() throws Exception {
		merchantBean = new TMerchant();
		return SUCCESS;
	}

	// 修改基本信息
	public String editinfo() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		} else {
			merchantBean = merchantService.fetch(merNo);
			return SUCCESS;
		}
	}

	// 修改银行账户
	public String editaccount() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		} else {
			merchantBean = merchantService.fetch(merNo);
			return SUCCESS;
		}
	}

	// 修改费率信息
	public String editfee() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		} else {
			merchantBean = merchantService.fetch(merNo);
			return SUCCESS;
		}
	}

	// 修改通道信息
	public String editbank() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		} else {
			merchantBean = merchantService.fetch(merNo);
			return SUCCESS;
		}
	}

	// 修改其他信息
	public String editother() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		} else {
			merchantBean = merchantService.fetch(merNo);
			return SUCCESS;
		}
	}

	// 登记商户
	public String save() throws Exception {
		if (merchantService.exist(merNo)) {
			addActionError("商户号已存在");
			return INFO;
		}
		merchantBean = new TMerchant();
		// 主信息
		merchantBean.setMerNo(merNo);
		merchantBean.setMerName(merName);
		merchantBean.setMerLevel(merLevel);
		merchantBean.setMerEmail(merEmail);
		merchantBean.setMerInfo(merInfo);
		merchantBean.setMerIndustry(merIndustry);
		merchantBean.setMerLink(merLink);
		merchantBean.setMerCredential(merCredential);
		merchantBean.setMerNumber(merNumber);
		merchantBean.setMerPhone(merPhone);
		merchantBean.setMerQq(merQq);
		merchantBean.setMerSource(merSource);
		merchantBean.setMerAddr(merAddr);
		merchantBean.setMerBanker(merBanker);
		merchantBean.setMerBank(merBank);
		merchantBean.setMerBranch(merBranch);
		merchantBean.setMerAccount(merAccount);

		// 生成费率信息
		merchantBean.setMerOpen(0D);
		merchantBean.setMerSum(1000000D);
		merchantBean.setMerPer(10000D);
		merchantBean.setMerDay(180D);
		merchantBean.setMerEnd(0D);
		merchantBean.setMerTop(3000D);
		merchantBean.setMerMin(25D);
		merchantBean.setMerMax(180D);
		merchantBean.setMerReturn(180D);
		merchantBean.setMerFreq(15D);
		merchantBean.setMerLimit(3000D);
		merchantBean.setMerConst(0D);
		merchantBean.setMerVenture(0D);
		merchantBean.setMerRefund(0D);
		merchantBean.setMerRefuse(130D);
		merchantBean.setMerVe("1");
		merchantBean.setMerVm("TSTEDC1001");
		merchantBean.setMerVb("1");
		merchantBean.setMerVs("TSTEDC1001");
		merchantBean.setMerVp(5D);
		merchantBean.setMerVd(10D);
		merchantBean.setMerMe("1");
		merchantBean.setMerMm("TSTEDC1001");
		merchantBean.setMerMb("1");
		merchantBean.setMerMs("TSTEDC1001");
		merchantBean.setMerMp(5D);
		merchantBean.setMerMd(10D);
		merchantBean.setMerJe("0");
		merchantBean.setMerJm("TSTEDC1001");
		merchantBean.setMerJb("0");
		merchantBean.setMerJs("TSTEDC1001");
		merchantBean.setMerJp(5D);
		merchantBean.setMerJd(10D);
		merchantBean.setMerAe("0");
		merchantBean.setMerAm("TSTEDC1001");
		merchantBean.setMerAb("0");
		merchantBean.setMerAs("TSTEDC1001");
		merchantBean.setMerAp(5D);
		merchantBean.setMerAd(10D);
		merchantBean.setMerCe("0");
		merchantBean.setMerCm("TSTEDC1001");
		merchantBean.setMerCb("0");
		merchantBean.setMerCs("TSTEDC1001");
		merchantBean.setMerCp(5D);
		merchantBean.setMerCd(10D);
		merchantBean.setMerDe("0");
		merchantBean.setMerDm("TSTEDC1001");
		merchantBean.setMerDb("0");
		merchantBean.setMerDs("TSTEDC1001");
		merchantBean.setMerDp(5D);
		merchantBean.setMerDd(10D);

		// 其他信息
		merchantBean.setMerRisking("0");
		merchantBean.setMerShipping("0");
		merchantBean.setMerMailing("0");
		merchantBean.setMerNotifying("0");
		merchantBean.setMerChilding("0");
		merchantBean.setMerLimiting("0");
		merchantBean.setMerDaying("0");
		merchantBean.setMerComparing("0");
		merchantBean.setMerCounting("0");
		merchantBean.setMerBrushing("0");
		merchantBean.setMerIgnoring("0");
		merchantBean.setMerVerifying("0");
		merchantBean.setMerRefunding("0");
		merchantBean.setMerReplacing("0");
		merchantBean.setMerUsing("0");

		merchantBean.setMerState("1");
		merchantBean.setMerDate(new Date());
		merchantBean.setMerRemark("");

		merchantService.persist(merchantBean);

		// 缺省子账户
		TSubject subjectBean = new TSubject();
		subjectBean.setSubNo(merNo);
		subjectBean.setSubName(CommonDict.SUBJECT_NAME);
		subjectBean.setSubPwd(AesUtil.AES_Encrypt(AesUtil.KEY, CommonDict.PASSWORD));
		subjectBean.setSubKey(KeyUtil.generate(CommonDict.KEY_LENGTH));
		subjectBean.setSubMenu(CommonDict.SUBJECT_MENU);
		subjectBean.setSubState("1");
		subjectBean.setSubDate(new Date());
		subjectBean.setSubRemark("");

		subjectService.persist(subjectBean);
		
		//缺省站内信
		TMail mailBean = new TMail();
		mailBean.setMalNo(StringUtil.guid());
		mailBean.setMerNo(merNo);
		mailBean.setMalInfo("欢迎使用本系统!<br/>商户在交易收单的过程中产生的退款拒付等资金变动信息,或者提现审核等财务信息,将通过站内信的方式进行提示,请注意接收最新的消息提醒.<br/><a href='merchant_show.html'>点击这里</a>查看商户的详细信息.");
		mailBean.setMalRead("0");
		mailBean.setMalState("1");
		mailBean.setMalDate(new Date());
		mailBean.setMalRemark("");
		mailService.persist(mailBean);
		return SUCCESS;
	}

	// 保存基本信息
	public String saveinfo() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		}
		merchantBean = merchantService.fetch(merNo);
		// 主信息
		merchantBean.setMerNo(merNo);
		merchantBean.setMerName(merName);
		merchantBean.setMerLevel(merLevel);
		merchantBean.setMerEmail(merEmail);
		merchantBean.setMerInfo(merInfo);
		merchantBean.setMerIndustry(merIndustry);
		merchantBean.setMerLink(merLink);
		merchantBean.setMerCredential(merCredential);
		merchantBean.setMerNumber(merNumber);
		merchantBean.setMerPhone(merPhone);
		merchantBean.setMerQq(merQq);
		merchantBean.setMerSource(merSource);
		merchantBean.setMerAddr(merAddr);
		merchantBean.setMerState(merState);
		merchantService.persist(merchantBean);
		return SUCCESS;
	}

	// 保存银行账户
	public String saveaccount() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		}
		merchantBean = merchantService.fetch(merNo);
		// 主信息
		merchantBean.setMerNo(merNo);
		merchantBean.setMerBanker(merBanker);
		merchantBean.setMerBank(merBank);
		merchantBean.setMerBranch(merBranch);
		merchantBean.setMerAccount(merAccount);
		merchantService.persist(merchantBean);
		return SUCCESS;
	}

	// 保存费率信息
	public String savefee() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		}
		merchantBean = merchantService.fetch(merNo);
		// 主信息
		merchantBean.setMerNo(merNo);
		merchantBean.setMerOpen(merOpen);
		merchantBean.setMerSum(merSum);
		merchantBean.setMerPer(merPer);
		merchantBean.setMerDay(merDay);
		merchantBean.setMerEnd(merEnd);
		merchantBean.setMerTop(merTop);
		merchantBean.setMerMin(merMin);
		merchantBean.setMerMax(merMax);
		merchantBean.setMerReturn(merReturn);
		merchantBean.setMerFreq(merFreq);
		merchantBean.setMerLimit(merLimit);
		merchantBean.setMerConst(merConst);
		merchantBean.setMerVenture(merVenture);
		merchantBean.setMerRefund(merRefund);
		merchantBean.setMerRefuse(merRefuse);
		merchantService.persist(merchantBean);
		return SUCCESS;
	}

	// 保存收单通道信息
	public String savebank() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		}
		merchantBean = merchantService.fetch(merNo);
		if (!bankService.exist(merVm)) {
			addActionError("V卡主通道不存在");
			return INFO;
		}
		if (!bankService.exist(merVs)) {
			addActionError("V卡备通道不存在");
			return INFO;
		}
		if (!bankService.exist(merMm)) {
			addActionError("M卡主通道不存在");
			return INFO;
		}
		if (!bankService.exist(merMs)) {
			addActionError("M卡备通道不存在");
			return INFO;
		}
		if (!bankService.exist(merJm)) {
			addActionError("J卡主通道不存在");
			return INFO;
		}
		if (!bankService.exist(merJs)) {
			addActionError("J卡备通道不存在");
			return INFO;
		}
		if (!bankService.exist(merAm)) {
			addActionError("A卡主通道不存在");
			return INFO;
		}
		if (!bankService.exist(merAs)) {
			addActionError("A卡备通道不存在");
			return INFO;
		}
		if (!bankService.exist(merCm)) {
			addActionError("C卡主通道不存在");
			return INFO;
		}
		if (!bankService.exist(merCs)) {
			addActionError("C卡备通道不存在");
			return INFO;
		}
		if (!bankService.exist(merDm)) {
			addActionError("D卡主通道不存在");
			return INFO;
		}
		if (!bankService.exist(merDs)) {
			addActionError("D卡备通道不存在");
			return INFO;
		}
		// 主信息
		merchantBean.setMerNo(merNo);
		merchantBean.setMerVe(merVe);
		merchantBean.setMerVm(merVm);
		merchantBean.setMerVb(merVb);
		merchantBean.setMerVs(merVs);
		merchantBean.setMerVp(merVp);
		merchantBean.setMerVd(merVd);
		merchantBean.setMerMe(merMe);
		merchantBean.setMerMm(merMm);
		merchantBean.setMerMb(merMb);
		merchantBean.setMerMs(merMs);
		merchantBean.setMerMp(merMp);
		merchantBean.setMerMd(merMd);
		merchantBean.setMerJe(merJe);
		merchantBean.setMerJm(merJm);
		merchantBean.setMerJb(merJb);
		merchantBean.setMerJs(merJs);
		merchantBean.setMerJp(merJp);
		merchantBean.setMerJd(merJd);
		merchantBean.setMerAe(merAe);
		merchantBean.setMerAm(merAm);
		merchantBean.setMerAb(merAb);
		merchantBean.setMerAs(merAs);
		merchantBean.setMerAp(merAp);
		merchantBean.setMerAd(merAd);
		merchantBean.setMerCe(merCe);
		merchantBean.setMerCm(merCm);
		merchantBean.setMerCb(merCb);
		merchantBean.setMerCs(merCs);
		merchantBean.setMerCp(merCp);
		merchantBean.setMerCd(merCd);
		merchantBean.setMerDe(merDe);
		merchantBean.setMerDm(merDm);
		merchantBean.setMerDb(merDb);
		merchantBean.setMerDs(merDs);
		merchantBean.setMerDp(merDp);
		merchantBean.setMerDd(merDd);
		merchantService.persist(merchantBean);
		return SUCCESS;
	}

	// 保存其他信息
	public String saveother() throws Exception {
		if (!merchantService.exist(merNo)) {
			addActionError("数据不存在");
			return INFO;
		}
		merchantBean = merchantService.fetch(merNo);
		// 主信息
		merchantBean.setMerNo(merNo);
		merchantBean.setMerRisking(merRisking);
		merchantBean.setMerShipping(merShipping);
		merchantBean.setMerMailing(merMailing);
		merchantBean.setMerNotifying(merNotifying);
		merchantBean.setMerChilding(merChilding);
		merchantBean.setMerLimiting(merLimiting);
		merchantBean.setMerDaying(merDaying);
		merchantBean.setMerComparing(merComparing);
		merchantBean.setMerCounting(merCounting);
		merchantBean.setMerBrushing(merBrushing);
		merchantBean.setMerIgnoring(merIgnoring);
		merchantBean.setMerVerifying(merVerifying);
		merchantBean.setMerRefunding(merRefunding);
		merchantBean.setMerReplacing(merReplacing);
		merchantBean.setMerUsing(merUsing);
		merchantService.persist(merchantBean);
		return SUCCESS;
	}

	// AUTOCOMPLATE功能
	public void auto() throws Exception {
		QuerySet<Object> querySet = new QuerySet<Object>();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("merNo", StringUtil.split(merNo));

		SortInfo sortInfo = new SortInfo();
		sortInfo.setSortField("merNo");
		sortInfo.setSortOrder(new Boolean(true));

		querySet.setPageInfo(new PageInfo(pageIndex, pageSize));
		querySet.setSortInfo(sortInfo);
		querySet.setParamMap(paramMap);

		ResultSet<TMerchant> resultSet = merchantService.search(querySet);
		merchantList = resultSet.getResultList();

		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html;charset=UTF-8");
		response.getWriter().println(JSONArray.fromObject(merchantList).toString());
	}

	public String list() throws Exception {
		QuerySet<Object> querySet = new QuerySet<Object>();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("merNo", StringUtil.split(merNo));
		paramMap.put("merName", merName);
		paramMap.put("merState", merState);
		paramMap.put("merDate", ParameterUtil.dateCombin(merDateTop, merDateEnd));

		SortInfo sortInfo = new SortInfo();
		sortInfo.setSortField((StringUtil.isEmpty(sortField)) ? "merDate" : sortField);
		sortInfo.setSortOrder(sortOrder);

		querySet.setPageInfo(new PageInfo(pageIndex, pageSize));
		querySet.setSortInfo(sortInfo);
		querySet.setParamMap(paramMap);

		ResultSet<TMerchant> resultSet = merchantService.search(querySet);
		merchantList = resultSet.getResultList();
		pageInfo = resultSet.getPageInfo();
		return SUCCESS;
	}

	public String listaccount() throws Exception {
		QuerySet<Object> querySet = new QuerySet<Object>();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("merNo", StringUtil.split(merNo));
		paramMap.put("merName", merName);
		paramMap.put("merBank", merBank);
		paramMap.put("merState", merState);
		paramMap.put("merDate", ParameterUtil.dateCombin(merDateTop, merDateEnd));

		SortInfo sortInfo = new SortInfo();
		sortInfo.setSortField((StringUtil.isEmpty(sortField)) ? "merDate" : sortField);
		sortInfo.setSortOrder(sortOrder);

		querySet.setPageInfo(new PageInfo(pageIndex, pageSize));
		querySet.setSortInfo(sortInfo);
		querySet.setParamMap(paramMap);

		ResultSet<TMerchant> resultSet = merchantService.search(querySet);
		merchantList = resultSet.getResultList();
		pageInfo = resultSet.getPageInfo();
		return SUCCESS;
	}

	public String listfee() throws Exception {
		QuerySet<Object> querySet = new QuerySet<Object>();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("merNo", StringUtil.split(merNo));
		paramMap.put("merName", merName);
		paramMap.put("merState", merState);
		paramMap.put("merDate", ParameterUtil.dateCombin(merDateTop, merDateEnd));

		SortInfo sortInfo = new SortInfo();
		sortInfo.setSortField((StringUtil.isEmpty(sortField)) ? "merDate" : sortField);
		sortInfo.setSortOrder(sortOrder);

		querySet.setPageInfo(new PageInfo(pageIndex, pageSize));
		querySet.setSortInfo(sortInfo);
		querySet.setParamMap(paramMap);

		ResultSet<TMerchant> resultSet = merchantService.search(querySet);
		merchantList = resultSet.getResultList();
		pageInfo = resultSet.getPageInfo();
		return SUCCESS;
	}

	public String listbank() throws Exception {
		QuerySet<Object> querySet = new QuerySet<Object>();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("merNo", StringUtil.split(merNo));
		paramMap.put("merName", merName);
		paramMap.put("merVm", merVm);
		paramMap.put("merVs", merVs);
		paramMap.put("merMm", merMm);
		paramMap.put("merMs", merMs);
		paramMap.put("merState", merState);
		paramMap.put("merDate", ParameterUtil.dateCombin(merDateTop, merDateEnd));

		SortInfo sortInfo = new SortInfo();
		sortInfo.setSortField((StringUtil.isEmpty(sortField)) ? "merDate" : sortField);
		sortInfo.setSortOrder(sortOrder);

		querySet.setPageInfo(new PageInfo(pageIndex, pageSize));
		querySet.setSortInfo(sortInfo);
		querySet.setParamMap(paramMap);

		ResultSet<TMerchant> resultSet = merchantService.search(querySet);
		merchantList = resultSet.getResultList();
		pageInfo = resultSet.getPageInfo();
		return SUCCESS;
	}

	public String listother() throws Exception {
		QuerySet<Object> querySet = new QuerySet<Object>();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("merNo", StringUtil.split(merNo));
		paramMap.put("merName", merName);
		paramMap.put("merState", merState);
		paramMap.put("merDate", ParameterUtil.dateCombin(merDateTop, merDateEnd));

		SortInfo sortInfo = new SortInfo();
		sortInfo.setSortField((StringUtil.isEmpty(sortField)) ? "merDate" : sortField);
		sortInfo.setSortOrder(sortOrder);

		querySet.setPageInfo(new PageInfo(pageIndex, pageSize));
		querySet.setSortInfo(sortInfo);
		querySet.setParamMap(paramMap);

		ResultSet<TMerchant> resultSet = merchantService.search(querySet);
		merchantList = resultSet.getResultList();
		pageInfo = resultSet.getPageInfo();
		return SUCCESS;
	}
	
	public String listmail() throws Exception {
		QuerySet<Object> querySet = new QuerySet<Object>();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("merNo", StringUtil.split(merNo));
		paramMap.put("merName", merName);
		paramMap.put("merState", merState);
		paramMap.put("merDate", ParameterUtil.dateCombin(merDateTop, merDateEnd));

		SortInfo sortInfo = new SortInfo();
		sortInfo.setSortField((StringUtil.isEmpty(sortField)) ? "merDate" : sortField);
		sortInfo.setSortOrder(sortOrder);

		querySet.setPageInfo(new PageInfo(pageIndex, pageSize));
		querySet.setSortInfo(sortInfo);
		querySet.setParamMap(paramMap);

		ResultSet<TMerchant> resultSet = merchantService.search(querySet);
		merchantList = resultSet.getResultList();
		pageInfo = resultSet.getPageInfo();
		return SUCCESS;
	}

	// 导出数据
	// 查询条件等同于列表查询条件
	public String export() throws Exception {
		QuerySet<Object> querySet = new QuerySet<Object>();

		HashMap<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("merNo", StringUtil.split(merNo));
		paramMap.put("merName", merName);
		paramMap.put("merState", merState);
		paramMap.put("merDate", ParameterUtil.dateCombin(merDateTop, merDateEnd));

		SortInfo sortInfo = new SortInfo();
		sortInfo.setSortField((StringUtil.isEmpty(sortField)) ? "merDate" : sortField);
		sortInfo.setSortOrder(sortOrder);

		querySet.setPageInfo(new PageInfo(1, CommonDict.EXPORT_LIMIT));
		querySet.setSortInfo(sortInfo);
		querySet.setParamMap(paramMap);

		ResultSet<TMerchant> resultSet = merchantService.search(querySet);
		merchantList = resultSet.getResultList();

		List<String> fieldHead = new ArrayList<String>();
		fieldHead.add("商户编号");
		fieldHead.add("名称");
		fieldHead.add("商户级别");
		fieldHead.add("邮箱");
		fieldHead.add("简介");
		fieldHead.add("所属行业");
		fieldHead.add("联系人");
		fieldHead.add("证件类型");
		fieldHead.add("证件号");
		fieldHead.add("联系手机");
		fieldHead.add("联系qq");
		fieldHead.add("推荐人");
		fieldHead.add("联系地址");
		fieldHead.add("开户人名");
		fieldHead.add("银行编码");
		fieldHead.add("支行名称");
		fieldHead.add("账户号");
		fieldHead.add("开户费");
		fieldHead.add("交易金额限制");
		fieldHead.add("交易笔数限制");
		fieldHead.add("交易天数限制");
		fieldHead.add("交易最低金额");
		fieldHead.add("交易最高金额");
		fieldHead.add("最低结算日期");
		fieldHead.add("最高结算日期");
		fieldHead.add("保证金返回天");
		fieldHead.add("提现周期");
		fieldHead.add("最低提现金额");
		fieldHead.add("单笔固定扣费");
		fieldHead.add("风险金费率");
		fieldHead.add("退款费");
		fieldHead.add("拒付费");
		fieldHead.add("v卡开通状态");
		fieldHead.add("v卡收单行");
		fieldHead.add("v卡备通道开通状态");
		fieldHead.add("v卡备收单行");
		fieldHead.add("v佣金费率");
		fieldHead.add("v押金比例");
		fieldHead.add("m卡开通状态");
		fieldHead.add("m卡收单行");
		fieldHead.add("m卡备通道开通状态");
		fieldHead.add("m卡备收单行");
		fieldHead.add("m佣金费率");
		fieldHead.add("m押金比例");
		fieldHead.add("j卡开通状态");
		fieldHead.add("j卡收单行");
		fieldHead.add("j卡备通道开通状态");
		fieldHead.add("j卡备收单行");
		fieldHead.add("j佣金费率");
		fieldHead.add("j押金比例");
		fieldHead.add("a卡开通状态");
		fieldHead.add("a卡收单行");
		fieldHead.add("a卡备通道开通状态");
		fieldHead.add("a卡备收单行");
		fieldHead.add("a佣金费率");
		fieldHead.add("a押金比例");
		fieldHead.add("c卡开通状态");
		fieldHead.add("c卡收单行");
		fieldHead.add("c卡备通道开通状态");
		fieldHead.add("c卡备收单行");
		fieldHead.add("c佣金费率");
		fieldHead.add("c押金比例");
		fieldHead.add("d卡开通状态");
		fieldHead.add("d卡收单行");
		fieldHead.add("d卡备通道开通状态");
		fieldHead.add("d卡备收单行");
		fieldHead.add("d佣金费率");
		fieldHead.add("d押金比例");
		fieldHead.add("是否开启第三方风控");
		fieldHead.add("是否自动发货");
		fieldHead.add("是否自动邮件");
		fieldHead.add("是否失败通知");
		fieldHead.add("是否报表显示子账户id");
		fieldHead.add("是否显示单笔限额");
		fieldHead.add("是否只显示n天内交易");
		fieldHead.add("是否校验ip和账单国家");
		fieldHead.add("是否开启交易笔数控制");
		fieldHead.add("是否刷单风险");
		fieldHead.add("是否忽略黑名单");
		fieldHead.add("是否忽略网站审核");
		fieldHead.add("是否24小时内免费退款");
		fieldHead.add("是否开启伪站");
		fieldHead.add("是否use");
		fieldHead.add("状态");
		fieldHead.add("日期日期");
		fieldHead.add("日期时间");
		fieldHead.add("备注");

		List<List<String>> fieldData = new ArrayList<List<String>>();

		for (TMerchant merchantBean : merchantList) {
			List<String> fieldItem = new ArrayList<String>();
			fieldItem.add(merchantBean.getMerNo());
			fieldItem.add(merchantBean.getMerName());
			fieldItem.add(merchantBean.getMerLevel());
			fieldItem.add(merchantBean.getMerEmail());
			fieldItem.add(merchantBean.getMerInfo());
			fieldItem.add(merchantBean.getMerIndustry());
			fieldItem.add(merchantBean.getMerLink());
			fieldItem.add(merchantBean.getMerCredential());
			fieldItem.add(merchantBean.getMerNumber());
			fieldItem.add(merchantBean.getMerPhone());
			fieldItem.add(merchantBean.getMerQq());
			fieldItem.add(merchantBean.getMerSource());
			fieldItem.add(merchantBean.getMerAddr());
			fieldItem.add(merchantBean.getMerBanker());
			fieldItem.add(merchantBean.getMerBank());
			fieldItem.add(merchantBean.getMerBranch());
			fieldItem.add(merchantBean.getMerAccount());
			fieldItem.add(merchantBean.getMerOpen().toString());
			fieldItem.add(merchantBean.getMerSum().toString());
			fieldItem.add(merchantBean.getMerPer().toString());
			fieldItem.add(merchantBean.getMerDay().toString());
			fieldItem.add(merchantBean.getMerEnd().toString());
			fieldItem.add(merchantBean.getMerTop().toString());
			fieldItem.add(merchantBean.getMerMin().toString());
			fieldItem.add(merchantBean.getMerMax().toString());
			fieldItem.add(merchantBean.getMerReturn().toString());
			fieldItem.add(merchantBean.getMerFreq().toString());
			fieldItem.add(merchantBean.getMerLimit().toString());
			fieldItem.add(merchantBean.getMerConst().toString());
			fieldItem.add(merchantBean.getMerVenture().toString());
			fieldItem.add(merchantBean.getMerRefund().toString());
			fieldItem.add(merchantBean.getMerRefuse().toString());
			fieldItem.add((merchantBean.getMerVe().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerVm());
			fieldItem.add((merchantBean.getMerVb().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerVs());
			fieldItem.add(merchantBean.getMerVp().toString());
			fieldItem.add(merchantBean.getMerVd().toString());
			fieldItem.add((merchantBean.getMerMe().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerMm());
			fieldItem.add((merchantBean.getMerMb().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerMs());
			fieldItem.add(merchantBean.getMerMp().toString());
			fieldItem.add(merchantBean.getMerMd().toString());
			fieldItem.add((merchantBean.getMerJe().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerJm());
			fieldItem.add((merchantBean.getMerJb().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerJs());
			fieldItem.add(merchantBean.getMerJp().toString());
			fieldItem.add(merchantBean.getMerJd().toString());
			fieldItem.add((merchantBean.getMerAe().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerAm());
			fieldItem.add((merchantBean.getMerAb().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerAs());
			fieldItem.add(merchantBean.getMerAp().toString());
			fieldItem.add(merchantBean.getMerAd().toString());
			fieldItem.add((merchantBean.getMerCe().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerCm());
			fieldItem.add((merchantBean.getMerCb().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerCs());
			fieldItem.add(merchantBean.getMerCp().toString());
			fieldItem.add(merchantBean.getMerCd().toString());
			fieldItem.add((merchantBean.getMerDe().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerDm());
			fieldItem.add((merchantBean.getMerDb().equals("0")) ? "无效" : "有效");
			fieldItem.add(merchantBean.getMerDs());
			fieldItem.add(merchantBean.getMerDp().toString());
			fieldItem.add(merchantBean.getMerDd().toString());
			fieldItem.add((merchantBean.getMerRisking().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerShipping().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerMailing().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerNotifying().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerChilding().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerLimiting().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerDaying().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerComparing().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerCounting().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerBrushing().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerIgnoring().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerVerifying().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerRefunding().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerReplacing().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerUsing().equals("0")) ? "无效" : "有效");
			fieldItem.add((merchantBean.getMerState().equals("0")) ? "无效" : "有效");
			fieldItem.add(DateUtil.format(merchantBean.getMerDate(), DateUtil.DATE));
			fieldItem.add(DateUtil.format(merchantBean.getMerDate(), DateUtil.TIME));
			fieldItem.add(merchantBean.getMerRemark());

			fieldData.add(fieldItem);
		}

		inputStream = ExcelUtil.excel(fieldHead, fieldData);
		return SUCCESS;
	}

	////////////////////// ---------------------------//////////////////////////////////////////////////////////////////////////////////////////////////////////////
	////////////////////// ---------------------------//////////////////////////////////////////////////////////////////////////////////////////////////////////////
	////////////////////// ---------------------------//////////////////////////////////////////////////////////////////////////////////////////////////////////////

	public IMerchantService getMerchantService() {
		return merchantService;
	}

	public void setMerchantService(IMerchantService merchantService) {
		this.merchantService = merchantService;
	}

	public ISubjectService getSubjectService() {
		return subjectService;
	}

	public void setSubjectService(ISubjectService subjectService) {
		this.subjectService = subjectService;
	}

	public IBankService getBankService() {
		return bankService;
	}

	public void setBankService(IBankService bankService) {
		this.bankService = bankService;
	}

	public TMerchant getMerchantBean() {
		return merchantBean;
	}

	public void setMerchantBean(TMerchant merchantBean) {
		this.merchantBean = merchantBean;
	}

	public List<TMerchant> getMerchantList() {
		return merchantList;
	}

	public void setMerchantList(List<TMerchant> merchantList) {
		this.merchantList = merchantList;
	}

	public String getMerNo() {
		return merNo;
	}

	public void setMerNo(String merNo) {
		this.merNo = merNo;
	}

	public String getMerName() {
		return merName;
	}

	public void setMerName(String merName) {
		this.merName = merName;
	}

	public String getMerLevel() {
		return merLevel;
	}

	public void setMerLevel(String merLevel) {
		this.merLevel = merLevel;
	}

	public String getMerEmail() {
		return merEmail;
	}

	public void setMerEmail(String merEmail) {
		this.merEmail = merEmail;
	}

	public String getMerInfo() {
		return merInfo;
	}

	public void setMerInfo(String merInfo) {
		this.merInfo = merInfo;
	}

	public String getMerIndustry() {
		return merIndustry;
	}

	public void setMerIndustry(String merIndustry) {
		this.merIndustry = merIndustry;
	}

	public String getMerLink() {
		return merLink;
	}

	public void setMerLink(String merLink) {
		this.merLink = merLink;
	}

	public String getMerCredential() {
		return merCredential;
	}

	public void setMerCredential(String merCredential) {
		this.merCredential = merCredential;
	}

	public String getMerNumber() {
		return merNumber;
	}

	public void setMerNumber(String merNumber) {
		this.merNumber = merNumber;
	}

	public String getMerPhone() {
		return merPhone;
	}

	public void setMerPhone(String merPhone) {
		this.merPhone = merPhone;
	}

	public String getMerQq() {
		return merQq;
	}

	public void setMerQq(String merQq) {
		this.merQq = merQq;
	}

	public String getMerSource() {
		return merSource;
	}

	public void setMerSource(String merSource) {
		this.merSource = merSource;
	}

	public String getMerAddr() {
		return merAddr;
	}

	public void setMerAddr(String merAddr) {
		this.merAddr = merAddr;
	}

	public String getMerBanker() {
		return merBanker;
	}

	public void setMerBanker(String merBanker) {
		this.merBanker = merBanker;
	}

	public String getMerBank() {
		return merBank;
	}

	public void setMerBank(String merBank) {
		this.merBank = merBank;
	}

	public String getMerBranch() {
		return merBranch;
	}

	public void setMerBranch(String merBranch) {
		this.merBranch = merBranch;
	}

	public String getMerAccount() {
		return merAccount;
	}

	public void setMerAccount(String merAccount) {
		this.merAccount = merAccount;
	}

	public Double getMerOpen() {
		return merOpen;
	}

	public void setMerOpen(Double merOpen) {
		this.merOpen = merOpen;
	}

	public Double getMerSum() {
		return merSum;
	}

	public void setMerSum(Double merSum) {
		this.merSum = merSum;
	}

	public Double getMerPer() {
		return merPer;
	}

	public void setMerPer(Double merPer) {
		this.merPer = merPer;
	}

	public Double getMerDay() {
		return merDay;
	}

	public void setMerDay(Double merDay) {
		this.merDay = merDay;
	}

	public Double getMerEnd() {
		return merEnd;
	}

	public void setMerEnd(Double merEnd) {
		this.merEnd = merEnd;
	}

	public Double getMerTop() {
		return merTop;
	}

	public void setMerTop(Double merTop) {
		this.merTop = merTop;
	}

	public Double getMerMin() {
		return merMin;
	}

	public void setMerMin(Double merMin) {
		this.merMin = merMin;
	}

	public Double getMerMax() {
		return merMax;
	}

	public void setMerMax(Double merMax) {
		this.merMax = merMax;
	}

	public Double getMerReturn() {
		return merReturn;
	}

	public void setMerReturn(Double merReturn) {
		this.merReturn = merReturn;
	}

	public Double getMerFreq() {
		return merFreq;
	}

	public void setMerFreq(Double merFreq) {
		this.merFreq = merFreq;
	}

	public Double getMerLimit() {
		return merLimit;
	}

	public void setMerLimit(Double merLimit) {
		this.merLimit = merLimit;
	}

	public Double getMerConst() {
		return merConst;
	}

	public void setMerConst(Double merConst) {
		this.merConst = merConst;
	}

	public Double getMerVenture() {
		return merVenture;
	}

	public void setMerVenture(Double merVenture) {
		this.merVenture = merVenture;
	}

	public Double getMerRefund() {
		return merRefund;
	}

	public void setMerRefund(Double merRefund) {
		this.merRefund = merRefund;
	}

	public Double getMerRefuse() {
		return merRefuse;
	}

	public void setMerRefuse(Double merRefuse) {
		this.merRefuse = merRefuse;
	}

	public String getMerVe() {
		return merVe;
	}

	public void setMerVe(String merVe) {
		this.merVe = merVe;
	}

	public String getMerVm() {
		return merVm;
	}

	public void setMerVm(String merVm) {
		this.merVm = merVm;
	}

	public String getMerVb() {
		return merVb;
	}

	public void setMerVb(String merVb) {
		this.merVb = merVb;
	}

	public String getMerVs() {
		return merVs;
	}

	public void setMerVs(String merVs) {
		this.merVs = merVs;
	}

	public Double getMerVp() {
		return merVp;
	}

	public void setMerVp(Double merVp) {
		this.merVp = merVp;
	}

	public Double getMerVd() {
		return merVd;
	}

	public void setMerVd(Double merVd) {
		this.merVd = merVd;
	}

	public String getMerMe() {
		return merMe;
	}

	public void setMerMe(String merMe) {
		this.merMe = merMe;
	}

	public String getMerMm() {
		return merMm;
	}

	public void setMerMm(String merMm) {
		this.merMm = merMm;
	}

	public String getMerMb() {
		return merMb;
	}

	public void setMerMb(String merMb) {
		this.merMb = merMb;
	}

	public String getMerMs() {
		return merMs;
	}

	public void setMerMs(String merMs) {
		this.merMs = merMs;
	}

	public Double getMerMp() {
		return merMp;
	}

	public void setMerMp(Double merMp) {
		this.merMp = merMp;
	}

	public Double getMerMd() {
		return merMd;
	}

	public void setMerMd(Double merMd) {
		this.merMd = merMd;
	}

	public String getMerJe() {
		return merJe;
	}

	public void setMerJe(String merJe) {
		this.merJe = merJe;
	}

	public String getMerJm() {
		return merJm;
	}

	public void setMerJm(String merJm) {
		this.merJm = merJm;
	}

	public String getMerJb() {
		return merJb;
	}

	public void setMerJb(String merJb) {
		this.merJb = merJb;
	}

	public String getMerJs() {
		return merJs;
	}

	public void setMerJs(String merJs) {
		this.merJs = merJs;
	}

	public Double getMerJp() {
		return merJp;
	}

	public void setMerJp(Double merJp) {
		this.merJp = merJp;
	}

	public Double getMerJd() {
		return merJd;
	}

	public void setMerJd(Double merJd) {
		this.merJd = merJd;
	}

	public String getMerAe() {
		return merAe;
	}

	public void setMerAe(String merAe) {
		this.merAe = merAe;
	}

	public String getMerAm() {
		return merAm;
	}

	public void setMerAm(String merAm) {
		this.merAm = merAm;
	}

	public String getMerAb() {
		return merAb;
	}

	public void setMerAb(String merAb) {
		this.merAb = merAb;
	}

	public String getMerAs() {
		return merAs;
	}

	public void setMerAs(String merAs) {
		this.merAs = merAs;
	}

	public Double getMerAp() {
		return merAp;
	}

	public void setMerAp(Double merAp) {
		this.merAp = merAp;
	}

	public Double getMerAd() {
		return merAd;
	}

	public void setMerAd(Double merAd) {
		this.merAd = merAd;
	}

	public String getMerCe() {
		return merCe;
	}

	public void setMerCe(String merCe) {
		this.merCe = merCe;
	}

	public String getMerCm() {
		return merCm;
	}

	public void setMerCm(String merCm) {
		this.merCm = merCm;
	}

	public String getMerCb() {
		return merCb;
	}

	public void setMerCb(String merCb) {
		this.merCb = merCb;
	}

	public String getMerCs() {
		return merCs;
	}

	public void setMerCs(String merCs) {
		this.merCs = merCs;
	}

	public Double getMerCp() {
		return merCp;
	}

	public void setMerCp(Double merCp) {
		this.merCp = merCp;
	}

	public Double getMerCd() {
		return merCd;
	}

	public void setMerCd(Double merCd) {
		this.merCd = merCd;
	}

	public String getMerDe() {
		return merDe;
	}

	public void setMerDe(String merDe) {
		this.merDe = merDe;
	}

	public String getMerDm() {
		return merDm;
	}

	public void setMerDm(String merDm) {
		this.merDm = merDm;
	}

	public String getMerDb() {
		return merDb;
	}

	public void setMerDb(String merDb) {
		this.merDb = merDb;
	}

	public String getMerDs() {
		return merDs;
	}

	public void setMerDs(String merDs) {
		this.merDs = merDs;
	}

	public Double getMerDp() {
		return merDp;
	}

	public void setMerDp(Double merDp) {
		this.merDp = merDp;
	}

	public Double getMerDd() {
		return merDd;
	}

	public void setMerDd(Double merDd) {
		this.merDd = merDd;
	}

	public String getMerRisking() {
		return merRisking;
	}

	public void setMerRisking(String merRisking) {
		this.merRisking = merRisking;
	}

	public String getMerShipping() {
		return merShipping;
	}

	public void setMerShipping(String merShipping) {
		this.merShipping = merShipping;
	}

	public String getMerMailing() {
		return merMailing;
	}

	public void setMerMailing(String merMailing) {
		this.merMailing = merMailing;
	}

	public String getMerNotifying() {
		return merNotifying;
	}

	public void setMerNotifying(String merNotifying) {
		this.merNotifying = merNotifying;
	}

	public String getMerChilding() {
		return merChilding;
	}

	public void setMerChilding(String merChilding) {
		this.merChilding = merChilding;
	}

	public String getMerLimiting() {
		return merLimiting;
	}

	public void setMerLimiting(String merLimiting) {
		this.merLimiting = merLimiting;
	}

	public String getMerDaying() {
		return merDaying;
	}

	public void setMerDaying(String merDaying) {
		this.merDaying = merDaying;
	}

	public String getMerComparing() {
		return merComparing;
	}

	public void setMerComparing(String merComparing) {
		this.merComparing = merComparing;
	}

	public String getMerCounting() {
		return merCounting;
	}

	public void setMerCounting(String merCounting) {
		this.merCounting = merCounting;
	}

	public String getMerBrushing() {
		return merBrushing;
	}

	public void setMerBrushing(String merBrushing) {
		this.merBrushing = merBrushing;
	}

	public String getMerIgnoring() {
		return merIgnoring;
	}

	public void setMerIgnoring(String merIgnoring) {
		this.merIgnoring = merIgnoring;
	}

	public String getMerVerifying() {
		return merVerifying;
	}

	public void setMerVerifying(String merVerifying) {
		this.merVerifying = merVerifying;
	}

	public String getMerRefunding() {
		return merRefunding;
	}

	public void setMerRefunding(String merRefunding) {
		this.merRefunding = merRefunding;
	}

	public String getMerUsing() {
		return merUsing;
	}

	public void setMerUsing(String merUsing) {
		this.merUsing = merUsing;
	}

	public String getMerState() {
		return merState;
	}

	public void setMerState(String merState) {
		this.merState = merState;
	}

	public Date getMerDate() {
		return merDate;
	}

	public void setMerDate(Date merDate) {
		this.merDate = merDate;
	}

	public Date getMerDateTop() {
		return merDateTop;
	}

	public void setMerDateTop(Date merDateTop) {
		this.merDateTop = merDateTop;
	}

	public Date getMerDateEnd() {
		return merDateEnd;
	}

	public void setMerDateEnd(Date merDateEnd) {
		this.merDateEnd = merDateEnd;
	}

	public String getMerRemark() {
		return merRemark;
	}

	public void setMerRemark(String merRemark) {
		this.merRemark = merRemark;
	}

	public IMailService getMailService() {
		return mailService;
	}

	public void setMailService(IMailService mailService) {
		this.mailService = mailService;
	}

	public String getMerReplacing() {
		return merReplacing;
	}

	public void setMerReplacing(String merReplacing) {
		this.merReplacing = merReplacing;
	}

	
	
}
